//
//  TKIMRootViewController.m
//  TKIM
//
//  Created by liupm on 15/8/11.
//  Copyright (c) 2015年 com.thinkive. All rights reserved.
//

#import "TKIMRootViewController.h"
//#import "TKIMColorHelper.h"
#import "TKIMChatViewController.h"
#import "TKIMLoginViewController.h"
#import "TKIMLayerUtils.h"
//#import "TKIMCacheHelper.h"
//#import "TKIMSDKHelper.h"

@interface TKIMRootViewController ()<UIAlertViewDelegate>
@property(nonatomic,strong)TKIMConverseViewController *main;
@property(nonatomic,strong) UINavigationController *mainNav;
@end

@implementation TKIMRootViewController

-(void)loadView
{
    [super loadView];
    //主界面
    _main = [[TKIMConverseViewController alloc] init];
    _mainNav = [[UINavigationController alloc] initWithRootViewController:_main];
    [self setNavStyle:_mainNav];
//    [self addChildViewController:_mainNav];
    [self.view addSubview:_mainNav.view];
    //个人热点问题修改
    _mainNav.view.frame = self.view.bounds;
    _main.view.frame = _mainNav.view.bounds;
    
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    //添加当前类对象为一个观察者，name和object设置为nil，表示接收一切通知
    [center addObserver:self selector:@selector(goH5:) name:TKIMSDK_GO_H5 object:nil];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}


-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
     self.navigationController.navigationBar.hidden = NO;
}


-(void)goH5:(NSNotification*)center
{
    NSDictionary* dict=center.userInfo;
    [super setViewDataInfo:dict];
    _main.viewDataInfo =self.viewDataInfo;
}


-(void)setViewDataInfo:(NSDictionary *)viewDataInfo
{
    [super setViewDataInfo:viewDataInfo];
    _main.viewDataInfo =self.viewDataInfo;
}


-(void)setNavStyle:(UINavigationController *)nav
{
    [nav.navigationBar setTranslucent:NO];
    if (self.barTintColor) {
        [nav.navigationBar setBarTintColor:self.barTintColor];
    }else{
        [nav.navigationBar setBarTintColor:[TKIMColorHelper stringToColor:@"#3B3A3E"]];
    }
    NSDictionary *navTitleArr = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [UIFont boldSystemFontOfSize:18],NSFontAttributeName,
                                 [UIColor whiteColor],NSForegroundColorAttributeName,
                                 nil];
    
    [nav.navigationBar setTintColor:[UIColor whiteColor]];
    [nav.navigationBar setTitleTextAttributes:navTitleArr];
}


#pragma mark 保持竖屏

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return NO;
}


-(BOOL)shouldAutorotate
{
    return NO;
}


@end
